package com.qdu.controller;

import com.alibaba.fastjson.JSONObject;
import com.qdu.bean.User;
import com.qdu.commons.AccessToken;
import com.qdu.util.EncryptUtil;
import com.qdu.commons.Result;
import com.qdu.service.PersonService;
import com.qdu.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/person")
public class PersonController {
    @Autowired
    PersonService personService;

    @RequestMapping("/getuser")
    public Result<User> getUser(HttpServletRequest request){
        String token = request.getHeader("token");
        String username = JWTUtil.getUsername(token);
        User user = personService.getUser(username);
        return Result.success(user);
    }

    @RequestMapping("/updateUser")
    public Result<String> updateUser(User user){
        personService.updateUser(user);
        return Result.success("成功修改");
    }

}
